/*Source

Problem Id:2685  User Id:Latex 
Memory:64K  Time:0MS
Language:G++  Result:Accepted

Source 
*/
#include <cstdio>
#include <cstring>

	int mxci[5];
	int n;
	char st[2][100];
	int ct;
	char name[5] = {' ', 'm', 'c', 'x', 'i'};
	
int out_mxci()
{
	int i, j, k;
	
	for (i=0; i<5; i++)
		printf("%d ", mxci[i]);
	printf(" -- mxci\n");
}
	
int get_ind(char c)
{
	if (c == 'm')
		return 1;
	if (c == 'c')
		return 2;
	if (c == 'x')
		return 3;
	if (c == 'i')
		return 4;
	return 0;
}

main()
{
	int i, j, k;
	int l;
	
//	freopen("p2685.in", "r", stdin);
//	freopen("p2685.out", "w", stdout);
	
	scanf("%ld", &n);
	
	for (ct=1; ct<=n; ct++)
	{
		scanf("%s%s", st[0], st[1]);
		memset(mxci, 0, sizeof(mxci));
		
		for (k=0; k<2; k++)
		{
			l = strlen(st[k]);
			for (i=0; i<l; i++)
			{
				if (!(st[k][i] <= '9' && st[k][i] >= '0'))
				{
					j = get_ind(st[k][i]);
					if (i == 0 || !(st[k][i-1] <='9' && st[k][i-1] >= '0'))
					{
						mxci[j] += 1;
					} else
					{
						mxci[j] += st[k][i-1] - '0';
					}
				}
			}	
			
			//debug
			//out_mxci();
		}
		
		for (i=4; i>=1; i--)
		{
			if (mxci[i] >= 10)
			{
				mxci[i-1]++;
				mxci[i] -= 10;
			}
		}
		
		//debug 
		//out_mxci();
		
		for (i=1; i<=4; i++)
		{
			if (mxci[i] > 0)
			{
				if (mxci[i] > 1)
				{
					printf("%d", mxci[i]);
				}
				printf("%c", name[i]);
			}
		}
		printf("\n");
	}
	return 0;
}

